import { Modal } from 'antd';
import PlankSelect from './PlankSelect';
import { useModel } from 'umi';
import { Order } from '@/types';

export function PlankSelectModule() {
  const { order, planks, reset, plank: lastPlank } = useModel('bom');
  return (
    <PlankSelect
      order={order ?? ({} as Order)}
      dataSource={planks}
      onConfirm={(plank) => {
        if (!lastPlank) {
          reset(plank);
          return;
        }
        Modal.confirm({
          title: '是否确认切换板件板件',
          content: '切换板件后，对上一板件的所有操作消失',
          onOk: () => {
            reset(plank);
          },
        });
      }}
    />
  );
}
